package com.zhongan.tb.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class FileUtils {

    public static final String DEFAULT_ENCODE = "UTF-8";

    /**
     * ���ж�ȡָ��·���ļ���List��
     *
     * @param fileName
     * @return
     */
    public static List<String> readByLineToList(String fileName) {
        return readByLineToList(fileName, DEFAULT_ENCODE);
    }

    /**
     * ���ж�ȡָ��·���ļ���List��
     *
     * @param fileName
     * @param encode
     * @return
     */
    public static List<String> readByLineToList(String fileName, String encode) {
        List<String> fileList = new ArrayList<>();
        if (null == fileName || fileName.isEmpty())
            return fileList;
        try {
            File file = new File(fileName);
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), encode);
                BufferedReader bufferedReader = new BufferedReader(read);
                String line = null;
                while ((line = bufferedReader.readLine()) != null) {
                    fileList.add(line);
                }
                read.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            return fileList;
        }
        return fileList;
    }


}
